const { Router } = require('express');
const query = require("../utils/query");

const router = Router();

router.get('/login', async (req, res) => {
    let sql = "SELECT l.id,l.time,u.user_name FROM login_log as l LEFT JOIN user as u ON u.id=l.user_id";
    if (req.query.startDay && req.query.endDay) {
        sql += ` WHERE l.time >= ? AND l.time <= ?`;
    }
    const data = await query(
        sql,
        [req.query.startDay, req.query.endDay]
    );
    res.send({
        code: 1,
        data
    });
});

router.get('/video', async (req, res) => {
    const data = await query("select l.id,l.time,u.user_name,v.name from video_log as l left join user as u on u.id=l.user_id left join video as v on v.id=l.video_id")
    res.send({
        code: 1,
        data
    })
});

module.exports = router;